import { apiService } from '../../api/apiService';
import { refreshrecord, RepairHandle, RepairDispatch, RepairAccept, RepairTransfer, getRepairRecord, getRepairType } from '../../api/server';
import { showSuccess } from '../../util/MessageDeal';
import { selfI18n } from '@/i18n';
export function getRepairDataSetup () {
    const repairDispatchtouser = (param, callback) => {
        apiService({
            api: RepairDispatch,
            param: { ...param },
            success: () => {
                showSuccess(selfI18n('wp_Dispatched_the_RR_successfully'));
                callback && callback();
            }
        });
    };
    const postrepairAccept = (param, callback) => {
        apiService({
            api: RepairAccept,
            param: { ...param },
            success: () => {
                showSuccess(selfI18n('wp_Accept_the_RR_successfully'));
                callback && callback();
            }
        });
    };
    const postrepairTransfer = (param, callback) => {
        apiService({
            api: RepairTransfer,
            param: { ...param },
            success: () => {
                showSuccess(selfI18n('wp_Transfer_the_RR_successfully'));
                callback && callback();
            }
        });
    };
    const getOneRepairRecord = (param) => {
        return new Promise((resolve, reject) => {
            apiService({
                api: getRepairRecord,
                param: { ...param },
                success: (data) => {
                    resolve(data);
                },
                fail: (data) => {
                    resolve(data);
                },
                error: (err) => {
                    reject(err);
                }
            });
        });
    };
    const getRepairTypeList = () => {
        return new Promise((resolve, reject) => {
            apiService({
                api: getRepairType,
                // param: { ...param },
                success: (data) => {
                    resolve(data);
                },
                fail: (data) => {
                    resolve(data);
                },
                error: (err) => {
                    reject(err);
                }
            });
        });
    };
    const refreshservicerecord = (param, callback) => {
        apiService({
            api: refreshrecord,
            param: { ...param },
            success: () => {
                showSuccess(selfI18n('wp_Update_completed'));
                callback && callback();
            }
        });
    };
    const handlerepair = (param, callback) => {
        apiService({
            api: RepairHandle,
            param: { ...param },
            success: () => {
                showSuccess(selfI18n('wp-jie-dan-cheng-gong'));
                callback && callback();
            }
        });
    };
    return {
        repairDispatchtouser,
        postrepairAccept,
        postrepairTransfer,
        getOneRepairRecord,
        getRepairTypeList,
        refreshservicerecord,
        handlerepair
    };
}
